package com.zl.controller;

import com.zl.model.PermissionDto;
import com.zl.model.common.ResponseBean;
import com.zl.service.IPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * PermissionController
 * @author zhoulang
 * @date 2018/8/29 15:45
 */
@RestController
@RequestMapping("permission")
public class PermissionController {

    @Autowired
    private IPermissionService iPermissionService;

    /**
     * 查询所有
     * @return ResponseBean
     */
    @GetMapping(value = "/listAll")
    public ResponseBean selectAll() {
        List<PermissionDto> list = iPermissionService.selectAll();
        return new ResponseBean(HttpStatus.OK.value(), "获取角色列表成功", list);
    }

    /**
     * 修菜单信息
     * @param rermissionDto 菜单实体
     * @return ResponseBean
     */
    @PostMapping(value = "/update")
    public ResponseBean update(@RequestBody PermissionDto rermissionDto) {
        iPermissionService.updateByPrimaryKey(rermissionDto);
        return new ResponseBean(HttpStatus.OK.value(), "修改角色信息成功", "");
    }

    /**
     * 菜单保存
     * @param rermissionDto 菜单实体类
     * @return ResponseBean
     */
    @PostMapping(value = "/save")
    public ResponseBean save(@RequestBody PermissionDto rermissionDto) {
        iPermissionService.insert(rermissionDto);
        return new ResponseBean(HttpStatus.OK.value(), "插入角色成功", "");
    }

    /**
     * 菜单的删除
     * @param ids 角色的id数组
     * @return ResponseBean
     */
    @PostMapping(value = "/delete")
    public ResponseBean delete(@RequestParam int ids[]) {
        iPermissionService.deletes(ids);
        return new ResponseBean(HttpStatus.OK.value(), "删除角色成功", "");
    }
}
